package org.lex.net.log;

import org.lex.net.log.Log.Type;
import org.lex.utils.text.DateTimeUtilities;

public class LogUnit {
	private long timeMillis = 0L;
	private Type type = Type.MISC;
	private Object source = null;
	private Object message = "";

	public LogUnit() {
		this(Type.MISC, null, "");
	}

	public LogUnit(Type type, Object source, Object message) {
		super();
		this.timeMillis = System.currentTimeMillis();
		this.type = type;
		this.source = source;
		this.message = message;
	}

	public Object getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getSource() {
		return source;
	}

	public void setSource(Object source) {
		this.source = source;
	}

	public long getTimeMillis() {
		return timeMillis;
	}

	public void setTimeMillis(long time) {
		this.timeMillis = time;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public String toString() {
		return this.toString(new StringBuilder()).toString();
	}

	public StringBuilder toString(StringBuilder builder) {
		builder.append('[').append(type.name()).append("]\t");
		builder.append(DateTimeUtilities.formatDateTime(timeMillis));
		builder.append('\t').append(source == null ? "" : source.toString());
		builder.append('\t').append(this.message);
		return builder;
	}
}
